package com.iflytek.service.impl;

import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iflytek.bean.Admin;
import com.iflytek.bean.Goods;
import com.iflytek.bean.StockInOrder;
import com.iflytek.mapper.GoodsMapper;
import com.iflytek.mapper.SioApproveMapper;
import com.iflytek.mapper.SooApproveMapper;
import com.iflytek.mapper.StockOutOrderMapper;
import com.iflytek.service.SioApproveService;
import com.iflytek.service.SooApproveService;
import com.iflytek.vo.StockInOrderVO;
import com.iflytek.vo.StockOutOrderVO;

@Service
public class SooApproveServiceImpl implements SooApproveService{
	@Autowired
	private SooApproveMapper SooapproveMapper;
	@Autowired
	private GoodsMapper goodMapper;
	@Autowired
	private StockOutOrderMapper orderMapper;
	@Override
	public List<StockOutOrderVO> selectByExample() {
		// TODO Auto-generated method stub
		return SooapproveMapper.selectByExample();
	}

	@Override
	public void updateApproveStatus(Integer id) {
		SooapproveMapper.updateApproveStatus(id);
	}

	@Override
	public List<StockOutOrderVO> selectByStatus1() {
		return SooapproveMapper.selectByStatus1();
	}

	@Override
	public StockOutOrderVO selectOrderById(Integer id) {
		// TODO Auto-generated method stub
		return SooapproveMapper.selectOrderById(id);
	}

	@Override
	public void updateGoodsNum(StockOutOrderVO order) {
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		order.setApprover(admin.getName());
		orderMapper.updateByPrimaryKeySelective(order);
		Goods good = goodMapper.selectByPrimaryKey(order.getGoodsId());
		if(good.getGoodsNum()-order.getGoodsNum()>=0) {
			good.setGoodsNum(good.getGoodsNum()- order.getGoodsNum());
			goodMapper.updateByPrimaryKeySelective(good);
		}else {
			System.out.println("error of num");
		}
	}

}
